package com.gzw.dms.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gzw.dms.R;
import com.gzw.dms.bean.DriverInfo;
import com.gzw.dms.bean.ShippingOrderInfo;

import java.util.List;

/**
 * Created by Administrator on 2016/9/2.
 */
public class DriverAdapter1 extends RecyclerView.Adapter {

    public static interface OnRecyclerViewListener {
        void onItemClick(int position);
        boolean onItemLongClick(int position);
    }
    private OnRecyclerViewListener onRecyclerViewListener;
    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
        this.onRecyclerViewListener = onRecyclerViewListener;
    }
    private static final String TAG = AbonrmalAdapter.class.getSimpleName();
    private List<DriverInfo> list;
    public DriverAdapter1(List<DriverInfo> list) {
        this.list = list;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_driveradapter, null);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        return new PersonViewHolder(view);
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        PersonViewHolder holder = (PersonViewHolder) viewHolder;
        holder.position = i;
        DriverInfo driverInfo = list.get(i);
        holder.ic_driver_name.setText("司机姓名:"+driverInfo.getDriver_name());
        holder.ic_cartype.setText("车辆类型:"+driverInfo.getDriver_cartype());
        holder.ic_phone.setText("联系方式:"+driverInfo.getDriver_phone());
        holder.ic_supplies.setText("供应商:"+driverInfo.getDriver_suppliersname());
        holder.ic_suppliescustom.setText("供应商公司:"+driverInfo.getSupplie_company());
        holder.ic_adress.setText("终到位置:"+driverInfo.getDriver_address());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class PersonViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
        public View rootView;
        public TextView ic_driver_name;
        public TextView ic_cartype;
        public TextView ic_phone;
        public TextView ic_suppliescustom;
        public TextView ic_supplies;
        public TextView ic_adress;

        public int position;
        public PersonViewHolder(View itemView) {
            super(itemView);
            ic_driver_name = (TextView) itemView.findViewById(R.id.ic_driver_name).findViewById(R.id.tv_name);
            ic_cartype = (TextView) itemView.findViewById(R.id.ic_cartype).findViewById(R.id.tv_name);
            ic_phone = (TextView) itemView.findViewById(R.id.ic_phone).findViewById(R.id.tv_name);
            ic_supplies = (TextView) itemView.findViewById(R.id.ic_supplies).findViewById(R.id.tv_name);
            ic_suppliescustom = (TextView) itemView.findViewById(R.id.ic_suppliescustom).findViewById(R.id.tv_name);
            ic_adress = (TextView) itemView.findViewById(R.id.ic_adress).findViewById(R.id.tv_name);
            rootView = itemView.findViewById(R.id.ll);
            rootView.setOnClickListener(this);
            rootView.setOnLongClickListener(this);
        }
        @Override
        public void onClick(View v) {
            if (null != onRecyclerViewListener) {
                onRecyclerViewListener.onItemClick(position);
            }
        }
        @Override
        public boolean onLongClick(View v) {
            if (null != onRecyclerViewListener) {
                return onRecyclerViewListener.onItemLongClick(position);
            }
            return false;
        }
    }
}
